package com.daxia.alipay.service;

import java.util.HashMap;
import java.util.Map;

import com.daxia.alipay.config.AlipayConfig;
import com.daxia.alipay.util.AlipaySubmit;
import com.daxia.ogmall.common.Logs;

public class AlipayService {
	
	/**
	 * 生成支付宝提交的form，由阿里巴巴官网 提供
	 * @param out_trade_no    订单编号 
	 * @param subject         订单名称
	 * @param total_fee       付款开发
	 * @param body            商品描述
	 * @return
	 */
	public String generateSubmitForm(String out_trade_no,String subject,String total_fee,String body) {
		//把请求参数打包成数组
  		Map<String, String> sParaTemp = new HashMap<String, String>();
  		sParaTemp.put("service", AlipayConfig.service);
        sParaTemp.put("partner", AlipayConfig.partner);
        sParaTemp.put("seller_id", AlipayConfig.seller_id);
        sParaTemp.put("_input_charset", AlipayConfig.input_charset);
  		sParaTemp.put("payment_type", AlipayConfig.payment_type);
  		sParaTemp.put("notify_url", AlipayConfig.notify_url);
  		sParaTemp.put("return_url", AlipayConfig.return_url);
  		sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);
  		sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
  		sParaTemp.put("out_trade_no", out_trade_no);
  		sParaTemp.put("subject", subject);
  		sParaTemp.put("total_fee", total_fee);
  		sParaTemp.put("body", body);
  		//其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
        //如sParaTemp.put("参数名","参数值");
  		
  		//建立请求
  		String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"post","确认");
  		return sHtmlText;
	}
	
	public static void main(String[] args) {
		 String out_trade_no = "BY1201611171532211994";

        //订单名称，必填
        String subject = "欧工支付";

        //付款金额，必填
        String total_fee = "1";

        //商品描述，可空
        String body = "这是一次支付";
        
        AlipayService service = new AlipayService();
        Logs.COMMON.debug(service.generateSubmitForm(out_trade_no, subject, total_fee, body));
	}
}